define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mall/order/myrefund/index',
                    add_url: 'mall/order/myrefund/add',
                    table: 'mall_order_refund',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                        {field: 'order_id', title: __('Order_id'), visible:false},
                        {field: 'orderNo', title: __('Orderno')},
                        {field: 'refundReson', title: __('Refundreson'), searchList: {"1":__('Refundreson 1'),"2":__('Refundreson 2'),"3":__('Refundreson 3'),"4":__('Refundreson 4'),"5":__('Refundreson 5'),"6":__('Refundreson 6'),"99":__('Refundreson 99')}, formatter: Table.api.formatter.normal},
                        {field: 'refundOtherReson', title: __('Refundotherreson'), visible:false},
                        {field: 'backMoney', title: __('Backmoney'), operate:'BETWEEN'},
                        {field: 'refundTo', title: __('Refundto')},
                        {field: 'refundTradeNo', title: __('Refundtradeno')},
                        {field: 'refundRemark', title: __('Refundremark'), visible:false},
                        {field: 'refundTime', title: __('Refundtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'refundStatus', title: __('Refundstatus'), searchList: {"1":__('Refundstatus 1'),"-1":__('Refundstatus -1'),"2":__('Refundstatus 2')}, formatter: Table.api.formatter.status},
                        {field: 'shopRejectReason', title: __('Shoprejectreason'), visible:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            //两个元素互相关联
            $("#c-refundReson").on("change", function () {
                if($("#c-refundReson").val()==99){
                    $(".frm-refundOtherReson").removeClass("hidden");
                    $("#c-refundOtherReson").focus();
                }
                else{
                    $(".frm-refundOtherReson").addClass("hidden");

                };
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});